package com.sc.nft.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.CopyrightAuctionUserBiddingDao;
import com.sc.nft.dao.UserInfoDao;
import com.sc.nft.entity.CopyrightAuctionUserBidding;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.dto.CopyrightAuctionUserBiddingAdminDataDTO;
import com.sc.nft.entity.dto.CopyrightAuctionUserBiddingAdminListDTO;
import com.sc.nft.entity.vo.CopyrightAuctionUserBiddingAdminDataVO;
import com.sc.nft.entity.vo.CopyrightAuctionUserBiddingAdminListVO;
import com.sc.nft.service.CopyrightAuctionUserBiddingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 版权拍卖出价表 服务实现类
 * </p>
 *
 * @author liGen
 * @since 2024-09-12
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class CopyrightAuctionUserBiddingServiceImpl implements CopyrightAuctionUserBiddingService {

    private final CopyrightAuctionUserBiddingDao copyrightAuctionUserBiddingDao;
    private final UserInfoDao userInfoDao;


    /**
     * 拍卖汇总记录
     * @return
     */
    @Override
    public CopyrightAuctionUserBiddingAdminDataVO copyrightAuctionRecordAdminData(CopyrightAuctionUserBiddingAdminDataDTO copyrightAuctionUserBiddingAdminDataDTO ) {
        List<CopyrightAuctionUserBidding> list = copyrightAuctionUserBiddingDao.getByRecordId(copyrightAuctionUserBiddingAdminDataDTO.getCopyrightAuctionRecordId());
        CopyrightAuctionUserBiddingAdminDataVO adminDataVO = new CopyrightAuctionUserBiddingAdminDataVO();
        if (CollectionUtils.isEmpty(list)) {
            return adminDataVO;
        }
        List<Long> userIdList = list.stream().map(CopyrightAuctionUserBidding::getUserId).distinct().collect(Collectors.toList());
        adminDataVO.setUserIdCount(userIdList.size());
        List<CopyrightAuctionUserBidding> collect = list.stream().filter(e ->e.getProgress() != null && e.getProgress()).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(collect)) {
            adminDataVO.setBiddingNum(collect.get(0).getBiddingNum());
            UserInfo userInfo = userInfoDao.getById(collect.get(0).getUserId());
            adminDataVO.setNickName(userInfo != null?userInfo.getUserTel():"");
        }
        return adminDataVO;
    }


    /**
     * 出价用户列表
     * @return
     */
    @Override
    public IPage<CopyrightAuctionUserBiddingAdminListVO> copyrightAuctionUserBiddingAdminList(CopyrightAuctionUserBiddingAdminListDTO copyrightAuctionUserBiddingAdminListDTO) {
        return copyrightAuctionUserBiddingDao.copyrightAuctionUserBiddingAdminList(copyrightAuctionUserBiddingAdminListDTO.getCopyrightAuctionRecordId(),copyrightAuctionUserBiddingAdminListDTO.getUserTel(), copyrightAuctionUserBiddingAdminListDTO.toMp(),copyrightAuctionUserBiddingAdminListDTO.getRoundId());
    }

}
